package 工厂方法模式;


import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class XMLUtilTV {
    public static Object getBean() {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = factory.newDocumentBuilder();
            Document doc = db.parse(new File("configTV.xml"));
            NodeList n1 = doc.getElementsByTagName("TVFactoryName");
            Node classNode = n1.item(0).getFirstChild();
            String TVFactoryName = classNode.getNodeValue().trim();

            //通过类名生成实列
            Class c = Class.forName(TVFactoryName);
            Object obj = c.newInstance();
            return obj;

        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }


    }
}
